package com.lw.leetcode.node;

import lombok.ToString;

/**
 * @Author liw
 * @Date 2021/4/16 9:58
 * @Version 1.0
 */
@ToString
public class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public static TreeNode getInstance() {

        //      1
        //     / \
        //   2    3
        //  / \    \
        // 4  5     6
        //   / \
        //  7  8
        TreeNode a = new TreeNode(1);
        TreeNode b = new TreeNode(2);
        TreeNode c = new TreeNode(3);
        TreeNode d = new TreeNode(4);
        TreeNode e = new TreeNode(5);
        TreeNode f = new TreeNode(6);
        TreeNode g = new TreeNode(7);
        TreeNode h = new TreeNode(8);
        a.left = b;
        a.right = c;
        b.left = d;
        b.right = e;
//        c.right = f;
//        e.left = g;
//        e.right = h;
        return a;
    }


    public static TreeNode getInstance2() {

        //      4
        //     / \
        //   2    5
        //  / \    \
        // 0  3     6

        TreeNode a = new TreeNode(4);
        TreeNode b = new TreeNode(2);
        TreeNode c = new TreeNode(5);
        TreeNode d = new TreeNode(1);
        TreeNode e = new TreeNode(3);
        TreeNode f = new TreeNode(6);
        a.left = b;
        a.right = c;
        b.left = d;
        b.right = e;
        c.right = f;
        return a;
    }

    public static TreeNode getInstance3() {

        //      5
        //     / \
        //   2    -5

        TreeNode a = new TreeNode(5);
        TreeNode b = new TreeNode(2);
        TreeNode c = new TreeNode(-2);

        a.left = b;
        a.right = c;

        return a;
    }
    public static TreeNode getInstance4() {

        //      5
        //     / \
        //   4    5
        //  / \    \
        // 1  1     5

        TreeNode a = new TreeNode(5);
        TreeNode b = new TreeNode(4);
        TreeNode c = new TreeNode(5);
        TreeNode d = new TreeNode(1);
        TreeNode e = new TreeNode(1);
        TreeNode f = new TreeNode(5);
        a.left = b;
        a.right = c;
        b.left = d;
        b.right = e;
        c.right = f;
        return a;
    }

    // [1,null,2,3,4,null,null,5,6]
    public static TreeNode getInstance5() {

        //      1
        //       \
        //        2
        //       / \
        //      3   4
        //         / \
        //        5  6
        TreeNode a = new TreeNode(1);
        TreeNode b = new TreeNode(2);
        TreeNode c = new TreeNode(3);
        TreeNode d = new TreeNode(4);
        TreeNode e = new TreeNode(5);
        TreeNode f = new TreeNode(6);
        a.right = b;
        b.left = c;
        b.right = d;
        d.left = e;
        d.right = f;
        return a;
    }
}
